<script>
	export default {
		onLaunch: function() {
			this.checkLogin()
		},
		onShow: function() {
			this.checkLogin()
		},
		onHide: function() {
		},

		methods: {
			checkLogin() {
				const token = uni.getStorageSync('token')
				const pages = getCurrentPages()
				const currentPage = pages[pages.length - 1]
				if (!token && currentPage) {
					const route = currentPage.route
					const needLoginPages = [
						// 'pages/user/user',
						// 'pages/order/detail',
						// 'pages/order/unshipped',
						// 'pages/order/shipping',
						// 'pages/order/completed',
						// 'pages/address/list',
						// 'pages/cart/cart',
						// 'pages/index/index',
					]
					if (needLoginPages.includes(route) && !route.includes('login')) {
						uni.redirectTo({
							url: '/pages/login/login'
						})
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	/* 引入 uview-plus 样式 */
	@import 'uview-plus/index.scss';

	@import '@/static/iconfont/iconfont.css';

	/* 这里可以添加其他全局样式 */
	page {
		background-color: #f8f8f8;
	}
</style>
